import { createApp } from "vue";
import App from "./App.vue";
import jQuery from "jquery";
import router from "./router";
// main.js
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import locale from "element-plus/dist/locale/zh-cn.js";
import ECharts from "vue-echarts";
const app = createApp(App);
import "echarts";
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
window.$ = window.jQuery = jQuery;

// 将 jQuery 挂载到 Vue 的原型上
app.config.globalProperties.$ = jQuery;
app.use(ElementPlus, { locale });
app.use(router); // 将 jQuery 挂载到全局对象 window 上

app.component("ECharts", ECharts);
app.mount("#app");

// 解决切换el-tab栏时出现的“ResizeObserver loop completed with undelivered notifications”的bug
const debounce = (fn, delay) => {
  let timer = null;
  return function () {
    let context = this;
    let args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
};

const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
  constructor(callback) {
    callback = debounce(callback, 16);
    super(callback);
  }
};
